<?php
/**
 * Created by PhpStorm.
 * User: Marmot
 * Date: 2018/5/10
 * Time: 10:18
 */
namespace app\admin\model;
use app\facade\Power;
use think\Model;
class Auth extends Model{
    //添加角色
    public function add_auth_role($data=array()){
        $res = $this ->table('d_auth_fun_role')->json(['role_res'])->insert($data);
//        echo $this->getLastSql();
        if ($res){
            return true;
        }else{
            return false;
        }
    }
    //获取角色列表
    public function get_auth_role($where='',$bool=true){
        $res = $this->table('d_auth_fun_role')->where($where)->json(['role_res'])->select()->toArray();
        if ($bool){
            foreach ($res as $key =>$value){
                $arr = [];
                if (!empty($value['role_res'])){
                    foreach ($value['role_res'] as $k =>$v){
                        $r = $this->table('d_nav')->field('nav_name')->where('id='.$v)->find();
                        $arr[] = $r['nav_name'];
                    }
                }
                $res[$key]['role_res'] = implode(' | ',$arr);
            }
        }
        return $res;
    }
    //
    //更新角色
    public function updata_auth_role($data=array(),$where=''){
        $res = $this ->table('d_auth_fun_role')->where($where)->update($data);
//        echo $auth->table('d_auth_fun_role')->getLastSql();
        if ($res){
            return true;
        }else{
            return false;
        }
    }

    /**
     * @param $w 查询模板表的条件
     * @param array $wh 角色表条件
     * @return array|bool
     */
    public function get_auth_model($auth_model,$wh=[]){
        return Power::get_auth_model($auth_model,$wh);
    }
}